package com.csd.action.teacher;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.ActionResult;
import com.csd.helper.IConstant;
import com.csd.helper.SessionManager;
import com.csd.pojo.ChangeRecord;
import com.csd.pojo.EvaluateItem;
import com.csd.pojo.Project;
import com.csd.service.IChangeRecordService;
import com.csd.service.IEvaluateItemService;
import com.csd.service.IProjectService;
import com.csd.serviceImpl.ChangeRecordService;
import com.csd.serviceImpl.EvaluateItemService;
import com.csd.serviceImpl.ProjectService;
import com.csd.vo.TeacherTaskVO;
import com.csd.vo.UserVO;

/**
 * 
 * 教师任务列表查询Action类
 * 
 * @author 尹华彬
 * @version 1.0
 * 
 * <br>
 *          修订时间：2009-12-17 <br>
 *          修改原因：创建文件 <br>
 *          修改人：尹华彬
 * 
 * <br>
 * 
 */
public class TeacherTaskListAction 
{
	// 老师任务列表的ID

	// 需要初期评审的项目
	List<TeacherTaskVO> evaluateProTask = null;
	// 需要变更审批的项目
	List<TeacherTaskVO> changeTask = null;
	// 需要结题审批的项目
	List<TeacherTaskVO> finishTask = null;
	//项目申请需要评审的项目
	List<TeacherTaskVO> projectApplyWaitReview = null;

	private IEvaluateItemService evaluateItemService;

	private IChangeRecordService changeRecordService;

	private IProjectService projectService;

	public IEvaluateItemService getEvaluateItemService() {
		return evaluateItemService;
	}

	public void setEvaluateItemService(IEvaluateItemService evaluateItemService) {
		this.evaluateItemService = evaluateItemService;
	}

	public IChangeRecordService getChangeRecordService() {
		return changeRecordService;
	}

	public void setChangeRecordService(IChangeRecordService changeRecordService) {
		this.changeRecordService = changeRecordService;
	}

	public IProjectService getProjectService() {
		return projectService;
	}

	public void setProjectService(IProjectService projectService) {
		this.projectService = projectService;
	}

	public List<TeacherTaskVO> getEvaluateProTask() {
		return evaluateProTask;
	}

	public void setEvaluateProTask(List<TeacherTaskVO> evaluateProTask) {
		this.evaluateProTask = evaluateProTask;
	}

	public List<TeacherTaskVO> getChangeTask() {
		return changeTask;
	}

	public void setChangeTask(List<TeacherTaskVO> changeTask) {
		this.changeTask = changeTask;
	}

	public List<TeacherTaskVO> getFinishTask() {
		return finishTask;
	}

	public void setFinishTask(List<TeacherTaskVO> finishTask) {
		this.finishTask = finishTask;
	}
	
	

	public List<TeacherTaskVO> getProjectApplyWaitReview() {
		return projectApplyWaitReview;
	}

	public void setProjectApplyWaitReview(List<TeacherTaskVO> projectApplyWaitReview) {
		this.projectApplyWaitReview = projectApplyWaitReview;
	}

	public String execute() 
	{
		String result = ActionResult.fail;
		Integer teacherID = null;

		System.out.println("come on");

		/*
		 * try { teacherID = SessionManager.getUserID(); } catch (Exception e) {
		 * e.printStackTrace(); return result; }
		 */
		teacherID = 1;
		//获得teacherID
		try 
		{
			HttpSession httpSession = ServletActionContext.getRequest().getSession();
			UserVO value = (UserVO)httpSession.getAttribute(IConstant.userVO);
			if(value == null)
			{
				throw  new Exception("用户未登录异常");
			}
			teacherID = value.getUserID();
		} catch (Exception e) 
		{
			e.printStackTrace();
			return result;
		}
		
		
		//获取需要指导老师审批的项目
		List<Project> waitReviewProjectList = projectService.listWaitReviewProjectByTeacherID(teacherID);
		projectApplyWaitReview = projectService.listProjectByFinalList(waitReviewProjectList);
		
		//获得老师需要评审的项目
		List<EvaluateItem> evaluateList = evaluateItemService
				.listEvaluateItemByTeacherID(teacherID);
		evaluateProTask = projectService.listProjectByList(evaluateList);
		
        //获得老师需要审批的变更
		List<ChangeRecord> changeList = null;
		System.out.println(changeRecordService);
		changeList = changeRecordService.listChangeRecordByTeacher(teacherID);
		System.out.println(changeList);
		if (changeList == null) {
			changeTask = null;
		} else {
			changeTask = projectService.listProjectByChangeList(changeList);
		}
		//获得老师需要批准结题的任务		
		List<Project> projectList = projectService.listFinTaskByTeacherID(teacherID);
		finishTask = projectService.listProjectByFinalList(projectList);
		result = ActionResult.success;
		return result;
	}

}
